package com.sszh.base.configurer.beans;

import com.sszh.base.mapper.KeyMapper;
import com.sszh.base.mapper.domain.KeyDO;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author WangJianGuo
 * @Title: InitializeBean
 * @Package com.sszh.base.configurer.beans
 * @Description: 全局初始化Bean
 * @date 2018-10-10 11:16
 */
@Component
@Log4j
@Data
public class InitializeBean{

    @Autowired
    KeyMapper keyMapper;

    private static InitializeBean initializeBean;

    /**
     * APP_ID
     */
    private Integer appId;

    /**
     * 加解密KEY
     */
    private String key;

    private InitializeBean(){
    }
    @PostConstruct
    public void  beforeInit(){
        log.info("初次加载initBean");
        KeyDO keyDO = keyMapper.getKey();
        initializeBean=new InitializeBean();
        initializeBean.setAppId(keyDO.getAppId());
        initializeBean.setKey(keyDO.getKey());
    }
    @Autowired
    public static InitializeBean getInstance(){
        return initializeBean;
    }

}
